<?php 

//Classe gameserver implémentant les méthodes de gestion des methodes relatives au serveur de jeu & de conn
// CLASSE ALLEGEE par rapport à l'originale !!!

class gameserver 
{
	
	public static function isWorldOnline()//-- Retouren faux si le serveur de jeu est hors ligne
	{
		$sock = @fsockopen(WORLD_HOST, WORLD_PORT_1, $errno, $errstr, 1) ;
		
		return $sock == false ? false : true ;
	}
	
	public static function isLogonOnline() //-- Retourne faux si le serveur de login est hors ligne.
	{
		$sock = @fsockopen(WORLD_HOST, LOGON_PORT, $errno, $errstr, 1) ;
		return $sock == false ? false : true ;
	}
	
	public static function getRealmNameOnSelectedPort($TCP_PORT_NUM)
	{
		$sql = core::getAuthSQL();
			$query = "SELECT SQL_CACHE name FROM realmlist WHERE port = '".$sql->real_escape_string($TCP_PORT_NUM)."' ";
		$stmt = $sql->query($query);
		if(!$stmt->num_rows) return false ;
		else {
			$r = $stmt->fetch_object();
			return $r ->name; 
		}
		
	}
	
	public static function getRealmNameByID($REALMID)
	{
		$sql = core::getAuthSQL();
			$query = "SELECT SQL_CACHE name FROM realmlist WHERE id = '".$sql->real_escape_string($REALMID)."' ";
		$stmt = $sql->query($query);
		if(!$stmt->num_rows) return false ;
		else {
			$r = $stmt->fetch_object();
			return $r ->name; 
		}
		
	}
	
	
	
	
	public function getAccountsMatchingPattern($pattern)
	{
		$sql = core::getAuthSQL();
		$sql->select_db(MYSQL_AUTH_DB);
			$query = "SELECT SQL_CACHE * FROM account WHERE
			id = '".$sql->real_escape_string($pattern)."'
			OR username LIKE '".$sql->real_escape_string($pattern)."%'
			OR last_ip LIKE '".$sql->real_escape_string($pattern)."%'
			OR email LIKE '".$sql->real_escape_string($pattern)."%'
			";
		$stmt = $sql->query($query);
		if(!$stmt->num_rows) return false;
		else 
		{
			$tab = NULL;
			while($tmp = $stmt->fetch_object())
			{
				$tab[] = $tmp;
			}
			return $tab;
		}
	}
	
	
	public static function getCharactersMatching($pattern)
	{
		$sql = core::getWorldSQL();
		$sql->select_db(MYSQL_WORLD_DB_CHARACTERS);
		$query = "SELECT SQL_CACHE guid, name FROM characters WHERE 
			guid = 	'".$sql->real_escape_string($pattern)."'
		OR name LIKE '".$sql->real_escape_string($pattern)."%' 
			
			ORDER BY name ASC";
		//echo $query;
		$exec = $sql->query($query);
		if(!$exec->num_rows) return false;
		else
		{	$tab = null;
			while($tmp = $exec->fetch_object())
			{
				$tab[] = $tmp;
			}
			return $tab;
		}
	}
	
	public static function getGuildsMatching($pattern)
	{
		$sql = core::getWorldSQL();
		$sql->select_db(MYSQL_WORLD_DB_CHARACTERS);
		$query = "SELECT SQL_CACHE guildid, name FROM guild WHERE 
			guildid = 	'".$sql->real_escape_string($pattern)."'
		OR name LIKE '".$sql->real_escape_string($pattern)."%' 
			
			ORDER BY name ASC";
		//echo $query;
		$exec = $sql->query($query);
		if(!$exec->num_rows) return false;
		else
		{	$tab = null;
			while($tmp = $exec->fetch_object())
			{
				$tab[] = $tmp;
			}
			return $tab;
		}
		
	}
	
}


?>